<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>漏洞修改</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form" lay-filter="assets_web_report_add">

            <div class="layui-form-item">
                <label class="layui-form-label" required>漏洞名称</label>
                <div class="layui-input-block">
                    <input type="text" name="ReportId" id="ReportId" class="layui-input layui-hide">
                    <input type="text" name="level_name" id="level_name" lay-verify="required" lay-reqtext="漏洞名称不能为空" placeholder="请输入漏洞名称" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">漏洞等级</label>
                <div class="layui-input-block">
                    <select name="level" id="level" lay-verify="">
                        <option value="1" selected>高危</option>
                        <option value="2">中危</option>
                        <option value="3">低危</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label required">整改情况</label>
                <div class="layui-input-block">
                    <select name="level_status" id="level_status" lay-verify="">
                        <option value="2" selected>未整改</option>
                        <option value="1">已整改</option>
                        <option value="3">已关闭</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="assets_report_edit">修改漏洞</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            laydate = layui.laydate;

        var AssetsReportId = localStorage.getItem("assetsReportId");
        if (AssetsReportId === ""){
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
        }
        $("#ReportId").attr("value", AssetsReportId);

        laydate.render({
            elem: '#ReportDataTime'
        });

        function GetReportInfo() {
            $.ajax({
                url: "/api/assets/reportinfo",
                dataType: 'json',
                type: 'post',
                data: JSON.stringify({"ID":AssetsReportId}),
                success: function (result) {
                    if (result.code == 200) {
                        $("#level_name").attr("value", result.data.level_name);
                        if(result.data.level===1){
                            $("#level").get(0).selectedIndex=0
                        }else if(result.data.level===2){
                            $("#level").get(0).selectedIndex=1
                        }else{
                            $("#level").get(0).selectedIndex=2
                        }
                        if(result.data.level_status===1){
                            $("#level_status").get(0).selectedIndex=1
                        }else if(result.data.level_status===2){
                            $("#level_status").get(0).selectedIndex=0
                        }else{
                            $("#level_status").get(0).selectedIndex=2
                        }
                        form.render();
                    } else {
                        layer.alert(result.msg, {
                            title: '提示',
                            icon: 2
                        })
                    }
                }
            });
        }
        GetReportInfo();

        //监听提交
        form.on('submit(assets_report_edit)', function(data) {
            $.ajax({
                url: "/api/assets/report/edit",
                data: JSON.stringify(data.field),
                contentType: 'application/json;charset=UTF-8',
                dataType: 'json',
                type: 'post',
                success: function(result) {
                    if (result.code == 200) {
                        var index = layer.alert("修改漏洞成功", {
                            title: '提示',
                            icon: 1
                        }, function() {
                            parent.layui.table.reload("currentTable_Report");
                            layer.close(index);
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        })
                    } else {
                        layer.alert(result.msg, {
                            title: '提示',
                            icon: 2
                        })
                    }
                },
                error: function (e) {
                    layer.alert(JSON.stringify(e), {title: '提示', icon: 2})
                }
            })
            return false;
        });
    });
</script>

</body>
</html>
